test(polylang): boot Polylang in the test bootstrap so its suite runs - #18
Merged
Conversation
Polylang 3.7+ requires src/api.php (which defines PLL() and the pll_* API) only from init_context(), and init() reaches init_context() only when it detects a context: admin, REST, or frontend-with-languages. Under PHPUnit there is no request context and languages are created per test (after Refresh_Database rolls them back), so init() saw an empty context, returned before loading the API, and PLL() stayed undefined. Every PolylangTest then skipped via markTestSkipped, leaving src/Integration/Polylang at 0% coverage. Force a frontend context through the pll_context filter so init_context() runs and loads the API. The whole PolylangTest suite now executes (0 -> ~79% line coverage on the Polylang integration).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18 +/- ##
============================================
+ Coverage 79.86% 87.42% +7.55%
Complexity 494 494
============================================
Files 31 31
Lines 1336 1336
============================================
+ Hits 1067 1168 +101
+ Misses 269 168 -101 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Coverage reports
src/Integration/Polylang/at 0%. EveryPolylangTestsilently skips viamarkTestSkipped('Polylang is not installed.'), becausefunction_exists('PLL')is false during the test run even though the plugin is installed.Root cause
Polylang 3.7+ loads its API (
PLL()and thepll_*functions, insrc/api.php) only fromPolylang::init_context().init()reachesinit_context()only when it detects a context — admin, REST, or frontend with languages defined.Under PHPUnit there is no request context, and languages are created per test (after
Refresh_Databaserolls them back), so at bootstrapinit()sees an empty context, returns before requiringsrc/api.php, andPLL()is never defined. The existing bootstrap call (new \Polylang(); ->init();) is therefore a no-op for loading the API.This surfaced after Polylang updated past its loader refactor (composer allows
^3.4; 3.8.4 is installed).Fix
Force a frontend context through Polylang's own
pll_contextfilter soinit_context()runs and loads the API. This completes the original intent —TestCase::setPolylangDefaultLanguage()already recreates languages per test, assuming Polylang booted once at bootstrap.Verification
src/Integration/Polylang/coverage: 0% → ~79% (88/112 statements); all six classes now exercised.PLUGINS=polylang … --testsuite=plugin-integration: 43 passed, 0 failures, no Polylang skips — un-skipping surfaced no real bugs.phpcsand PHPStan clean ontests/bootstrap.php.$isPolylang, so non-Polylang suites are unaffected.